package com.susallwave.srcb.serviceimpl.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.susallwave.srcb.entity.sys.RolePermission;
import com.susallwave.srcb.mapper.sys.RolePermissionMapper;
import com.susallwave.srcb.response.Result;
import com.susallwave.srcb.service.sys.RolePermissionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 角色权限关系表 服务实现类
 * </p>
 *
 * @author MyBatisPlusGenerator
 * @since 2025-07-20
 */
@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
    @Override
    public List<RolePermission> rolePermissions(String roleCode) {
        return this.list(new LambdaQueryWrapper<RolePermission>().eq(RolePermission::getRoleCode,roleCode));
    }

    @Override
    public Result<IPage<RolePermission>> listPermissions(int pageNum, int pageSize, String roleCode, String permissionCode) {
        Page<RolePermission> page = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<RolePermission> qw = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(roleCode)) {
            qw.eq(RolePermission::getRoleCode, roleCode);
        }
        if (StringUtils.isNotBlank(permissionCode)) {
            qw.eq(RolePermission::getPermissionCode, permissionCode);
        }
        return Result.success(this.page(page,qw));
    }

    @Override
    public Result<Void> setPermissions(String roleCode, List<String> permissionCode) {
        return null;
    }
}
